package com.lzs.Service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lzs.DAO.AreaDAO;
import com.lzs.DAO.MechanismDAO;
import com.lzs.PO.Area;
import com.lzs.PO.Mechanism;
import com.lzs.PO.Page;
import com.lzs.Service.MechanismService;


@Service
public class MechanismServiceImpl implements MechanismService{

	@Autowired
	
	 MechanismDAO mechanismDAO;
	
		public Page<Mechanism> findMechanismPagelist(String keyword, Integer pageSize, Integer pageNum) {

			List<Mechanism> mechanismlist = this.mechanismDAO.findMechanismList(keyword);

			int totalRecord = mechanismlist.size();

			Page<Mechanism> page = new Page<Mechanism>(pageNum, pageSize, totalRecord);

			int startIndex = page.getStartIndex();

			page.setList(mechanismDAO.findMechanismPagelist(keyword, startIndex, pageSize));
			
			return page;
		}

		@Override
		public void addMechanism(Map<String, Object> map) {
			
			this.mechanismDAO.addMechanism(map);
			
		}

		@Override
		public Boolean countMechanismByName(String mechanism_name) {
			
			long count = this.mechanismDAO.countMechanismByName(mechanism_name);
			
			return count==0;
		}

		@Override
		public Mechanism findMechanismById(String mechanism_id) {
			
			Mechanism mechanism = this.mechanismDAO.findMechanismById(mechanism_id);
			
			return mechanism;
		}

		@Override
		public void updateMechanismById(Map<String, Object> map) {
			
			this.mechanismDAO.updateMechanismById(map);
			
		}

		@Override
		public void deleteMechanismById(String mechanism_id) {
			
			this.mechanismDAO.deleteMechanismById(mechanism_id);
			
		}
	}


